<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <img id="img" src="../assets/images/111.png" alt="">
    <div id="goal"></div>
    <script>
        var imgDom = document.getElementById('img')
        var goal = document.getElementById('goal')

        // 开始拖动
        imgDom.ondragstart = function (e) {
            console.log(e.pageX, "pageX");
            e.dataTransfer.setData('text/plain', e.target.id)
        }

        // 目标位置：拖动过程
        goal.ondragover = function (e) {
            e.preventDefault();
        }

        // 目标位置：拖动结束
        goal.ondrop = function (e) {
            e.preventDefault()
            const idName = e.dataTransfer.getData('text/plain')
            var dropDom = document.getElementById(idName)
            goal.appendChild(dropDom)
        }
    </script>
</body>
<style>
    #goal {
        margin: auto;
        width: 200px;
        height: 200px;
        border: 2px solid #333;
    }
</style>

</html>